package com.gy.algorithm.carl.dp;

/**
 * @BelongsProject: javabase
 * @BelongsPackage: com.gy.algorithm.carl.dp
 * @Author: gy
 * @Date: 2024/10/24 15:13
 * @Description:
 */
public class GetKthMagicNumber17_09 {

    public static int getKthMagicNumber(int k) {
        if(k <  1) return 0;

        int[] res = new int[k];
        int index3 = 0 ,index5 = 0,index7 =0;
        res[0] = 1;
        int min = Integer.MIN_VALUE;

        for (int i = 1; i < res.length; i++) {
            min = Math.min(3 * res[index3],Math.min(5 * res[index5],7 * res[index7]));
            if(3 * res[index3] == min) index3++;
            if(5 * res[index5] == min) index5++;
            if(7 * res[index7] == min) index7++;
            res[i] = min;
        }

        return res[k - 1];

    }
}
